package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.activity.xiuxian.data.CrossXiuXianRank;
import com.yanqu.road.entity.activity.xiuxian.data.CrossXiuXianRankListModel;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.manager.activity.xiuxian.CrossXiuXianMgr;
import com.yanqu.road.server.manager.activity.xiuxian.activity.CrossXiuXianActivity;

import java.util.LinkedList;

public class XiuXianActivityRank extends BaseCrossRank {

    public XiuXianActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        // 个人仙力
        int conditionType = eGamePlayerEventType.XiuXianXianLiRank.getValue();
        CrossActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityNewRankListModel(activityId, conditionType);
        if (rankListModel != null) {
            int rank = 0;
            for (CrossUserRank rankData : rankListModel.getRankList()) {
                long userId = rankData.getUserId();
                rank++;
                addUserRankData(msg, conditionType, userId, rank);
            }
        }
        CrossXiuXianActivity activity = CrossXiuXianMgr.getActivity(activityId);
        if (activity != null) {
            // 个人战绩榜单
            CrossXiuXianRankListModel userRank = activity.getUserScoreRank();
            if (userRank != null) {
                LinkedList<CrossXiuXianRank> rankList = userRank.getRankList();
                int rankNum = 0;
                for (CrossXiuXianRank rank : rankList) {
                    rankNum++;
                    long userId = Long.parseLong(rank.getId());
                    addUserRankData(msg, eGamePlayerEventType.XiuXianPersonalScoreRank.getValue(), userId, rankNum);
                }
            }
        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        return getCrossNormalActivityUnionRankMsg();
    }

}
